#include "grpceventdef.h"
#include "jsonwrapper.h"


nlohmann::json DeleteAlarmsParam::SerializeToJsonArray()
{
    return ::CreateJsonArray(alarms);
}

bool DeleteAlarmsParam::ParseFromJsonArray(const nlohmann::json &json)
{
    try {

        // 反序列化到 C++ 对象
        alarms = json[0].get<std::list<std::string>>();
        return true;
    } catch (...) {
        qCritical() << "Parse DeleteAlarmsParam Err Str = " << json.dump().c_str();
    }
    return false;
}

nlohmann::json ResShelfTaskParam::SerializeToJsonArray()
{
    return ::CreateJsonArray(shelfNum, waitToGo);
}

bool ResShelfTaskParam::ParseFromJsonArray(const nlohmann::json &json)
{
    try {
        // 反序列化到 C++ 对象
        shelfNum = json[0].get<int>();
        waitToGo = json[1].get<std::list<std::string >>();
        return true;
    } catch (...) {
        qCritical() << "Parse ResShelfTaskParam Err Str = " << json.dump().c_str();
    }
    return false;
}

nlohmann::json NotifyMcuStatusParam::SerializeToJsonArray()
{
    return ::CreateJsonArray(mcuId, status);
}

bool NotifyMcuStatusParam::ParseFromJsonArray(const nlohmann::json &json)
{
    try {
        // 反序列化到 C++ 对象
        mcuId = json[0].get<std::string>();
        status = json[1].get<int>();
        return true;
    } catch (...) {
        qCritical() << "Parse NotifyMcuStatusParam Err Str = " << json.dump().c_str();
    }
    return false;
}

nlohmann::json RunStatusReportParam::SerializeToJsonArray()
{
    return ::CreateJsonArray(status);
}

bool RunStatusReportParam::ParseFromJsonArray(const nlohmann::json &json)
{
    try {
        // 反序列化到 C++ 对象
        status = json[0].get<int>();
        return true;
    } catch (...) {
        qCritical() << "Parse RunStatusReportParam Err Str = " << json.dump().c_str();
    }
    return false;
}

nlohmann::json AlarmReportParam::SerializeToJsonArray()
{
    return ::CreateJsonArray(type, alarmLevel, alarmId, alarmName, alarmTime);
}

bool AlarmReportParam::ParseFromJsonArray(const nlohmann::json &json)
{
    try {
        // 反序列化到 C++ 对象
        type = json[0].get<int>();
        alarmLevel = json[1].get<int>();
        alarmId = json[2].get<std::string>();
        alarmName = json[3].get<std::string>();
        alarmTime = json[4].get<std::string>();
        return true;
    } catch (...) {
        qCritical() << "Parse AlarmReportParam Err Str = " << json.dump().c_str();
    }
    return false;
}

nlohmann::json ShelfInfoParam::SerializeToJsonArray()
{
    return ::CreateJsonArray(ulShelfNum, tubes);
}

bool ShelfInfoParam::ParseFromJsonArray(const nlohmann::json &json)
{
    try {
        // 反序列化到 C++ 对象
        ulShelfNum = json[0].get<int>();
        tubes = json[1].get<std::list< CTubeInfo >>();
        return true;
    } catch (...) {
        qCritical() << "Parse ShelfInfoParam Err Str = " << json.dump().c_str();
    }
    return false;
}
